<template>
	<view class="u-p-b-20 bg-white" v-if="seckillList.length">
		<view class="flex align-center justify-between" @click="moreSeckill">
			<u-cell-item :borderBottom="false" value="更多" hoverClass="none" >
				<view class="flex align-center" slot="title">
					<u-image src="/static/index/home_time_skill.png" width="137rpx" mode="widthFix"></u-image>
					<view class="u-m-l-20" style="margin-top: -5rpx;">
						<u-count-down ref="uCountDown" bgColor="var(--mainColor)" color="#fff" fontSize="30" :timestamp="endTime"></u-count-down>
					</view>
				</view>
			</u-cell-item>
		</view>
		<view class="u-p-x-20">
			<view class="flex align-center justify-between" :class="{'item-flex':seckillList.length<=2}" >
				<view v-for="(item,index) in seckillList.slice(0,3)" :key="index" @click="toSeckill(item)">
					<view class="flex flex-column rounded box-shadow" style="width: 230rpx;">
						<u-image style="border: 1rpx solid #eaeaea;" :src="item.goods_image" width="230rpx" height="230rpx" borderRadius="10"></u-image>
						<view class="flex flex-column u-p-10">
							<text class="font-sm text-ellipsis">{{item.goods_name}}</text>
							<text class="u-p-y-8 text-danger">¥ {{item.price}}</text>
							<text class="text-greey text-through">原价：¥ {{item.line_price}}</text>
						</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import { SeckillCenterApi } from '@/api/serves.js'
	export default {
		name: "index-seckill",
		data() {
			return {
				endTime: '',
				seckillList: [],
				room_id: '',
			}
		},
		methods: {
			getCalendar(){
			  SeckillCenterApi.getCalendar().then(res=>{
			    console.log('秒杀专场',res)
			    if(res.code==1){
						this.endTime = res.data.daojishi
						if(res.data.rooms.length>0) {
							this.room_id = res.data.rooms[0].id
							SeckillCenterApi.getRoomGoods({ room_id: res.data.rooms[0].id}).then(res=>{
							  console.log('秒杀商品',res)
							  if(res.code==1){
							    this.seckillList = res.data
							  }
							})
						}
			    }
			  })
			},
			moreSeckill() {
				uni.navigateTo({
					url: '/pages/seckill/seckillMore/seckillMore'
				})
			},
			toSeckill(item) {
				let params = {
					id: item.id,
					room_id: this.room_id,
					goods_id: item.goods_id
				}
				uni.navigateTo({
					url: '/pages/seckill/seckillGoodsDetail/seckillGoodsDetail?info=' + JSON.stringify(params)
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	::v-deep.u-countdown-item {
		padding: 5rpx 10rpx;
		border-radius: 8rpx;
	}
	.u-cell[data-v-65423b64] {
		padding: 10rpx 20rpx;
	}
	.item-flex::after{
		content: ''; 
		width: 230rpx; 
		border:1px solid transparent; 
	}
</style>
